component{
	include "../../inc/lib.cfm"; 

	public any function list(rc){
		
		var result = {};
		var offset = (rc.page-1)*rc.rows;
		hql = "from adstemplate where " & rc.sqlWhere & rc.sqlSort;
		var result["rows"] = ormExecuteQuery(hql, false, {maxResults=rc.rows, offset=offset});
		var totalhql = "select count(id) as total from adstemplate where " & rc.sqlWhere ;
		var result["total"] = ormExecuteQuery(totalhql, true);
		
		return result;
	}
	

	public any function preview(rc){
		var result = {};
		var hql = " from adsmaterial where id in (#rc.checkedids#) order by seq asc,id asc";
		var result["rows"]= ormExecuteQuery(hql,false);
		var result["templateurl"] = get( lsparsenumber(rc.templateid) ).geturl();
		
		for(i = 1; i <= arraylen(result.rows); i++)
		{
			if(!isnull(result.rows[i].getPic())){
				var e = entityLoadByPk("uploader",  result.rows[i].getPic());
				result.rows[i]['img'] = e.getservername();
			}
		}
		
		return result;
	}

	public any function get(numeric id){
		result = entityLoadByPk("adstemplate", arguments.id);
		return result;
	}

}